<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 构造函数继承: 通过调用父类(构造函数),强制将this指向子类(构造函数)调用过程创建的实例化对象  ParentClass.call(this,arg1...argN)

    // 优点: 可以实现父类 实例相关的属性和方法的继承
    // 缺点: 只能继承实例相关,无法继承原型对象相关的属性和方法

    function Person(name, age) {
        // this -> 指向构造函数Person执行过程中创建的实例化对象
        this.name = name;
        this.age = age;
    }

    Person.prototype.species = "human";
    Person.prototype.skill = function () {
        console.log("thinking");
    };
    Person.prototype.say = function () {
        console.log(this.name, this.age);
    };

    // p的原型链: p -> Person.prototype -> Object.prototype ->  null 
    var p = new Person("张三", 18);
    console.log(p);

    function YellowPerson(name, age, hobby) {
        // this -> 指向构造函数YellowPerson执行过程中创建的实例化对象
        Person.call(this, name, age);
        this.hobby = hobby;
    };

    YellowPerson.prototype = Person.prototype;

    //先继承父元素的，再定义自己的
    YellowPerson.prototype.speak = function () {
        console.log("chinese");
    };

    var yp = new YellowPerson("王五", 88, "pc");
    console.log(yp);
    console.log(yp.species);
    yp.skill();
</script>

</html>